package lightswitch.client.code.model;

import java.util.Vector;

import javax.swing.table.AbstractTableModel;

public class MyTableModel extends AbstractTableModel {
    public Vector<String> columnNames;
    public Vector<Vector<Object>> dataVector;
    
    public MyTableModel(Vector<String> cn, Vector<Vector<Object>> dv) {
        super();
        dataVector = dv;
        columnNames = cn;
    }
    
    public void resetTableModel(Vector<String> cn, Vector<Vector<Object>> dv) {
        dataVector = dv;
        columnNames = cn;
    }
    
    @Override
    public int getColumnCount() {
        // TODO Auto-generated method stub
        return columnNames.size();
    }

    @Override
    public int getRowCount() {
        // TODO Auto-generated method stub
        return dataVector.size();
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        // TODO Auto-generated method stub
        return dataVector.get(rowIndex).get(columnIndex);
    }
    
    public String getColumnName(int col) {
        return columnNames.get(col);
    }
    
    public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }
    
    public boolean isCellEditable(int row, int col) {
        return false;
    }
    
    public void setValueAt(Object value, int row, int col) {
        Vector<Object> rowVector = dataVector.get(row);
        rowVector.set(col, value);
        dataVector.set(row, rowVector);
    }
}
